/*
** main.c for  in /home/marion_v/tek2/psu-rush1-2015-marion_v/epikong/etape_1
**
** Made by vincent marioni
** Login   <marion_v@epitech.net>
**
** Started on  Sat Mar  3 04:16:43 2012 vincent marioni
** Last update Sat Mar  3 06:03:02 2012 vincent marioni
*/

#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>

#include "alum1.h"

static void		aff_alumm(SDL_Surface *ecran, SDL_Surface *image)
{
  SDL_Event	event;
  SDL_Rect	pos_img;

  pos_img.x=200;
  pos_img.y=50;
  SDL_EnableKeyRepeat(1, 1);
  while (1)
    {
      SDL_WaitEvent(&event);
      if(event.type == SDL_KEYDOWN)
	{
	  if(event.key.keysym.sym == SDLK_UP)
	    pos_img.y--;
	  if(event.key.keysym.sym == SDLK_DOWN)
	    pos_img.y++;
	  if(event.key.keysym.sym == SDLK_LEFT)
	    pos_img.x--;
	  if(event.key.keysym.sym == SDLK_RIGHT)
	    pos_img.x++;
	}
      if(event.key.keysym.sym == SDLK_ESCAPE)
	break;
      if(event.type == SDL_QUIT)
	break;
      SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 0));
      SDL_BlitSurface(image, NULL, ecran, &pos_img);
      SDL_Flip(ecran);
    }
  exit(EXIT_SUCCESS);
}


int		main()
{
  SDL_Surface	*ecran;
  SDL_Surface	*image;
  SDL_Surface	*wall = NULL;
  SDL_Surface	*enemy = NULL;
  /* SDL_Surface	*player = NULL; */
  /* SDL_Surface	*scale = NULL; */
  /* SDL_Surface	*key = NULL; */
  /* SDL_Surface	*input = NULL; */
  /* SDL_Surface	*output = NULL; */
  /* SDL_Rect	position, positionJoueur; */

  SDL_WM_SetIcon(SDL_LoadBMP("sprite/.bmp"), NULL);

  ecran = NULL;
  /* image_loader(image, wall, enemy); */
  image = IMG_Load("sprites/Mario.gif");
  wall = IMG_Load("sprites/Bricks.gif");
  enemy = IMG_Load("sprites/Goomba_Grey.gif");

  SDL_WM_SetCaption("Prout", NULL);
  SDL_SetColorKey(image, SDL_SRCCOLORKEY, SDL_MapRGB(image->format, 100, 50, 0)); //Transparence
  SDL_SetColorKey(wall, SDL_SRCCOLORKEY, SDL_MapRGB(wall->format, 20, 20, 255)); //Transparence
  SDL_SetColorKey(enemy, SDL_SRCCOLORKEY, SDL_MapRGB(enemy->format, 5, 5, 255)); //Transparence
  SDL_Init(SDL_INIT_VIDEO);
  ecran = SDL_SetVideoMode(1024, 640, 32, SDL_HWSURFACE);
  aff_alumm(ecran, image);
  aff_alumm(ecran, wall);
  aff_alumm(ecran, enemy);
  SDL_FreeSurface(image);
  SDL_FreeSurface(wall);
  SDL_FreeSurface(enemy);
  SDL_Quit();
  return EXIT_SUCCESS;
}
